<?php
class ModelConfigBussness extends Model {
	public function addBussness($data) {
		$sql = "INSERT INTO `" . DB_PREFIX . "config_bussness_type` SET ".
		"type_name = '" . $this->db->escape($data['type_name'])."',description='".$data['description']."',code='".$data['code']."'";
		echo $sql;
		$this->db->query($sql);
	}
	
	public function editBussness($bussness_type_id, $data) {
		$this->db->query("UPDATE `" . DB_PREFIX . "config_bussness_type` SET ".
		"type_name = '" . $this->db->escape($data['type_name']) ."',description='".$data['description']."',code='".$data['code']."' WHERE bussness_type_id = '" . (int)$bussness_type_id . "'");
	}
	
	
	public function getTotalBussnesss() {
      	$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "config_bussness_type`");
		return $query->row['total'];
	}
	
	public function getBussness($bussness_type_id) {
		$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "config_bussness_type` WHERE bussness_type_id = '" . (int)$bussness_type_id . "'");
		return $query->row;
	}
	
	public function getAllBussnesss($data=array()){
		$sql = "SELECT * FROM `" . DB_PREFIX . "config_bussness_type`";
			
		$sort_data = array(
			'date_added'
		);	
			
		$query = $this->db->query($sql);
	
		return $query->rows;
	}
	
	public function deleteBussness($bussness_type_id) {
		$this->db->query("DELETE FROM `" . DB_PREFIX . "config_bussness_type` WHERE bussness_type_id = '" . (int)$bussness_type_id . "'");
	}
	
	public function getBussnesss($data = array()) {
		$sql = "SELECT * FROM `" . DB_PREFIX . "config_bussness_type`";
			
		$sort_data = array(
			'date_added'
		);	
			
		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}			
			
			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}	
			
			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}
			
		$query = $this->db->query($sql);
	
		return $query->rows;
	}
	
}
?>